from urllib import request
import numpy as np
import os

os.chdir(r'E:\作业')  # 设置该路径为当前路径

url = 'https://www.biedoul.com/index/'

header = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36'}
pages = np.array([x for x in range(10)]) + 1530
print(pages)
for page in pages:
    url = url + str(page)
    re = request.Request(url, headers=header)
    resp = request.urlopen(re)
    # request.urlretrieve(resp.read(),str(page)+".txt")
    with open(str(page) + ".html", 'wb') as f:  # 以流的方式打开文件
        f.write(resp.read())  # 写入文件
